package org.lvxiao.example.list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ArrayListDemo {

	public static void main(String[] args) {
		int size = 1000000;
		List<Integer> list = new ArrayList<>(size);
		for(int i = 0; i < size; i++) {
			list.add(i);
		}
		long startTime = System.currentTimeMillis();
		for(int i = 0; i < size; i++) {
			list.get(i);
		}
		long endTime = System.currentTimeMillis();
		System.out.println("For-Get:" + (endTime-startTime));
		
		startTime = System.currentTimeMillis();
		Iterator<Integer> iterator = list.iterator();
		while(iterator.hasNext()) {
			iterator.next();
		}
		endTime = System.currentTimeMillis();
		System.out.println("itr迭代器：" + (endTime-startTime));
		
		iterator = list.listIterator();
		startTime = System.currentTimeMillis();
		while(iterator.hasNext()) {
			iterator.next();
		}
		endTime = System.currentTimeMillis();
		System.out.println("ListItr迭代器：" + (endTime-startTime));
		
		startTime = System.currentTimeMillis();
		list.forEach( item -> {});
		endTime = System.currentTimeMillis();
		System.out.println("lambda foreach: " + (endTime-startTime));
		
		startTime = System.currentTimeMillis();
		for(Integer item :list) {
			
		}
		endTime = System.currentTimeMillis();
		System.out.println("foreach:" + (endTime-startTime));
	}
	
}
